package com.wd.live.view.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.wd.live.R
import com.wd.live.databinding.ActivityMainBinding
import com.wd.live.viewmodel.LoginViewModel
import com.wd.live.wxapi.BaseConstant
import com.wd.live.wxapi.LoginHelper
import com.wd.live.wxapi.WXEntryActivity

class MainActivity : AppCompatActivity() {
    private var wxApi: IWXAPI? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var binding = ActivityMainBinding.inflate(layoutInflater)
        val root = binding.root
        setContentView(root)
        binding.LoginDeal.setOnClickListener {
            startActivity(Intent(this, DealActivity::class.java))
        }
        val box = binding.LoginCheck

        binding.LoginButton.setOnClickListener {
            if (box.isChecked) {
                //Toast.makeText(this,"登录成功", Toast.LENGTH_SHORT).show()
                //startActivity(Intent(this, WXEntryActivity::class.java))
                wxApi?.let { it1 ->
                    LoginViewModel().getWxCode(it1)}
                }else{
                    Toast.makeText(this, "请先勾选协议", Toast.LENGTH_SHORT).show()
                }
            }
    }
    private fun initWx() {
        //初始化微信
        wxApi = WXAPIFactory.createWXAPI(this, BaseConstant.WX_APP_ID, false)
        wxApi?.registerApp(BaseConstant.WX_APP_ID)
    }
//    override fun onResume() {
//        super.onResume()
//        LoginHelper.getWxLoginCode(applicationContext)?.let {
//            LoginViewModel.doLogin(it)
//        }
//    }

}